package main

import (
	"encoding/json"
	"fmt"
)

type PersonBean struct {
	Name string `json:"name"` //添加标签
	Age  int    `json:"age"`
	Sex  bool   `json:"sex"`
}

func main() {
	var person = PersonBean{Name: "张三", Age: 18}
	//转成json
	str, err := json.Marshal(person)
	if err != nil {
		panic(err)
	}
	fmt.Printf("json: %s \n", str)
	fmt.Println(string(str))
	var jsonStr = "{\"Name\":\"张三1\",\"Age\":28,\"Sex\":false,\"aa\":123} "

	var pp = PersonBean{}
	//json转成结构体
	json.Unmarshal([]byte(jsonStr), &pp)
	fmt.Printf("pp:%v \n", pp)
}
